package com.example.easeimpro.controller.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.example.easeimpro.R;
import com.example.easeimpro.controller.fragment.ChatFragment;
import com.example.easeimpro.controller.fragment.OptionFragment;
import com.example.easeimpro.controller.fragment.QunFragment;
import com.example.easeimpro.model.bean.Model;
import com.hyphenate.EMCallBack;
import com.hyphenate.chat.EMClient;
import com.hyphenate.chat.EMOptions;
import com.hyphenate.exceptions.HyphenateException;

public class MainActivity extends AppCompatActivity {
    private Handler handler = new Handler();
    private static final String TAG = "MainActivity";
    private RadioButton btnHui;
    private RadioGroup groupList;
    private RadioButton btnOption;
    private ChatFragment chatFragment;
    private QunFragment qunFragment;
    private OptionFragment optionFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    initView();
     initData();
    initOnClick();
    }

    private void initOnClick() {

        groupList.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                Fragment fragment = null;

             switch (checkedId){
                 case R.id.main_btn_hui: switchFragmentView(chatFragment); break;
                 case R.id.main_btn_qun: switchFragmentView(qunFragment) ;break;
                 case R.id.main_btn_op: switchFragmentView(optionFragment);break;

             }


            }
        });
    }

    public void switchFragmentView(Fragment fragment){//切换当前的fragment
        FragmentTransaction replace = getSupportFragmentManager().beginTransaction().replace(R.id.fl_layout, fragment);

        replace.commit();
    }
    private void initData() {
        chatFragment = new ChatFragment();
        qunFragment = new QunFragment();
        optionFragment = new OptionFragment();
        switchFragmentView(chatFragment);
    }

    private void initView() {
        groupList = findViewById(R.id.main_group_list);
        btnHui = findViewById(R.id.main_btn_hui);//会话
        btnHui.setChecked(true);

    }


}